﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.WebPages;

namespace MMSWebsite
{
    /// <summary>
    /// Device specific startup configuration
    /// </summary>
    public static class DeviceConfig
    {
        const string DeviceTypePhone = "Phone";               
        const string DeviceTypeTablet = "Tablet";
        const string DeviceTypeWindowPhone = "WP7";
        const string DeviceTypeAndroid = "AND";


        /// <summary>
        /// Evaluates incoming request and determines device.
        /// Adds an entry into the Display mode table
        /// </summary>
        public static void EvaluateDisplayMode()
        {
            DisplayModeProvider.Instance.Modes.Insert(0,
                new DefaultDisplayMode(DeviceTypePhone)
                {  //modify file (view that is served)

                    //Query condition
                    ContextCondition = (ctx => (

                        //look at user agent
                        (ctx.GetOverriddenUserAgent() != null) &&

                        (//...either iPhone or iPad

                            ctx.GetOverriddenUserAgent().Contains("iPhone") ||
                            ctx.GetOverriddenUserAgent().Contains("IP")
                        )
                ))
                });

            DisplayModeProvider.Instance.Modes.Insert(0,
                new DefaultDisplayMode(DeviceTypeTablet)
                {
                    ContextCondition = (ctx => (

                        (ctx.GetOverriddenUserAgent() != null) &&

                        (
                            ctx.GetOverriddenUserAgent().Contains("iPad") ||
                            ctx.GetOverriddenUserAgent().Contains("Playbook")
                        )

                ))
                });

            DisplayModeProvider.Instance.Modes.Insert(0,
               new DefaultDisplayMode(DeviceTypeWindowPhone)
               {
                   ContextCondition = (ctx => (

                       (ctx.GetOverriddenUserAgent() != null) &&

                       (
                           ctx.GetOverriddenUserAgent().Contains("Window Phone")
                       )

               ))
               });

            DisplayModeProvider.Instance.Modes.Insert(0,
              new DefaultDisplayMode(DeviceTypeAndroid)
              {
                  ContextCondition = (ctx => (

                      (ctx.GetOverriddenUserAgent() != null) &&

                      (
                          ctx.GetOverriddenUserAgent().Contains("Android")
                      )

              ))
              });
        }
    }
}